<template>
    <div class="form-container" style="padding-top: 0px !important;">
        <exAddEdit ref="exAddEdit" v-model="model"></exAddEdit>

        <div style="display: block;text-align: center;">
            <el-button v-if="isAdd" @click="resetThisVal('model')">{{comLan["btnReset"]}}</el-button>
            <el-button @click="closeCurrent">{{comLan["btnCancel"]}}</el-button>
            <el-button type="primary" @click="save" :loading="loading">{{comLan["btnSave"]}}</el-button>
        </div>
    </div>
</template>

<script>
    import common from "@/common/common.js";
    import js from "./js.js";
    import exAddEdit from "@/Auto/SampleDisplay/SampleDisplayAddEdit.vue";

    export default {
        name: "SampleDisplayAddRedict",
        components: {
            exAddEdit
        },
        mixins: [common.baseVM, js],
        data() {
            return {
                model: {
                    SampleDisplayID: 0,
                    TablesID: null,
                    SampleDisplayName: null,
                    ImageUrl: null,
                    ImageUrl2: null,
                    IsDefault: false,
                    OrderID: null,
                    EnumStatus: 1,
                    Remark: null,
                }
            }
        },
        methods: {
            init() {
                this.loadBeforeValSuccess = false;
                this.resetVal("model");
                var query = this.getQuery();
                var id = parseInt(query["id"]);
                if (isNaN(id)) id = 0;
                this.isAdd = id == 0;
                if (this.isAdd) { //新建
                    this.loadBeforeVal();
                    return;
                }
                this.get("api/SampleDisplay/Get?id=" + id).then(data => {
                    this.model = data.Result;
                });
            },
            closeCurrent() {
                this.refreshList("/SampleDisplay/SampleDisplayList");
            },
            save() {
                this.$refs.exAddEdit.formValidate('formModel', () => {
                    var post = JSON.parse(JSON.stringify(this.model));
                    this.loading = true;
                    this.post('api/SampleDisplay/Save', post).then(data => {
                        this.showToast(data.Message, "success");
                        this.loading = false;
                        
                        this.clearBeforeVal();
                        this.closeCurrent();
                    }).catch((error) => {
                        this.loading = false;
                    });
                });
            }
        }
    }
</script>
